package com.test.dababy.dababy_00_utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.test.dababy.R;


public class UploadingDialog extends Dialog {


    private String dRH5="";
    private String cDYU="";
    private boolean a86u=true;
    private String a5ZT="";
    private String vt9R="";
    private String jn3U="";
    private float pSY3=0.021736383f;
    private String a75L="";
    private String epZ9="";
    private boolean ol99=true;
    private String nV8t="";
    private char kn3G='d';

    public void dGdK5(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getdRH5()))
                    setcDYU(isA86u() +getA5ZT()+getVt9R()+getJn3U()+getpSY3());
                else setA75L(getEpZ9() + isOl99() + getnV8t() + getKn3G());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setdRH5(String dRH5) {
        this.dRH5 = dRH5;
    }

    public void setcDYU(String cDYU) {
        this.cDYU = cDYU;
    }

    public void setA86u(boolean a86u) {
        this.a86u = a86u;
    }

    public void setA5ZT(String a5ZT) {
        this.a5ZT = a5ZT;
    }

    public void setVt9R(String vt9R) {
        this.vt9R = vt9R;
    }

    public void setJn3U(String jn3U) {
        this.jn3U = jn3U;
    }

    public void setpSY3(float pSY3) {
        this.pSY3 = pSY3;
    }

    public void setA75L(String a75L) {
        this.a75L = a75L;
    }

    public void setEpZ9(String epZ9) {
        this.epZ9 = epZ9;
    }

    public void setOl99(boolean ol99) {
        this.ol99 = ol99;
    }

    public void setnV8t(String nV8t) {
        this.nV8t = nV8t;
    }

    public void setKn3G(char kn3G) {
        this.kn3G = kn3G;
    }

    public String getdRH5() {
        return dRH5;
    }

    public String getcDYU() {
        return cDYU;
    }

    public boolean isA86u() {
        return a86u;
    }

    public String getA5ZT() {
        return a5ZT;
    }

    public String getVt9R() {
        return vt9R;
    }

    public String getJn3U() {
        return jn3U;
    }

    public float getpSY3() {
        return pSY3;
    }

    public String getA75L() {
        return a75L;
    }

    public String getEpZ9() {
        return epZ9;
    }

    public boolean isOl99() {
        return ol99;
    }

    public String getnV8t() {
        return nV8t;
    }

    public char getKn3G() {
        return kn3G;
    }

    private ImageView rotateIv;

    public UploadingDialog(@NonNull Context context) {
        super(context);
    }

    private static boolean isShowing = false;

    private Thread rotateThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_dababy_uploading);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        rotateIv = findViewById(R.id.ddu_iv_rotate);

    }

    @Override
    public void show() {

        if (isShowing) return;

        super.show();

        isShowing = true;

        dGdK5();
        startRotate();
    }

    @Override
    public void dismiss() {
        stopRotate();
        super.dismiss();
        isShowing = false;
    }


    private void startRotate(){

        float centerX = rotateIv.getWidth()/2f;
        float centerY = rotateIv.getHeight()/2f;

        rotateIv.setPivotX(centerX);
        rotateIv.setPivotY(centerY);

        rotateThread = new Thread(() -> {
            try {
                Thread.sleep(241);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            DababyUtil.safeRun(() -> rotateIv.setRotation(60));
        });

        rotateIv.setRotation(60);

        rotateThread.start();

    }

    private void stopRotate(){
        if (rotateThread!=null&&rotateThread.isAlive()) rotateThread.interrupt();
    }

}
